package com.secneo.appshare.threads;

import java.io.ByteArrayOutputStream;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.kaixin.connect.Kaixin;
import com.secneo.appshare.R;
import com.secneo.appshare.api.LocalStore;
import com.secneo.appshare.api.RemoteApi.UserInfo;
import com.secneo.appshare.api.impl.RemoteApiImpl;
import com.secneo.appshare.common.ActivityUtil;
import com.secneo.appshare.common.Constants;

// step 1  获得request token
public class LoginKaixinThread extends Thread {

	private Handler handler;
	private Context ctx;
	
	public LoginKaixinThread(Context ctx, Handler handler) 
	{
		this.ctx = ctx;
		this.handler = handler;
	}
	
	public void run() 
	{
		try 
		{
			Kaixin kaixin = Kaixin.getInstance();
			String[] permissions = { "basic", "create_records" };
			boolean success = kaixin.getRequestToken(ctx, "kxapibbfxdemo://apidemos", permissions);
			if(success){
				
				Message msg = new Message();
				msg.what = 201;//获取开心requestToken成功
				handler.sendMessage(msg);
				
				/*
				Uri uri = Uri.parse(Kaixin.KX_AUTHORIZE_URL
						+ "?oauth_token=" + kaixin.getRequestToken()
						+ "&oauth_client=1");
				ctx.startActivity(new Intent(Intent.ACTION_VIEW, uri));
				*/
			}
		}
		catch (Exception ex) {
			Log.d("MyTag", "Exception: "+ex.getMessage());
		}
			
	}
}
